﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1;
using System.IO.IsolatedStorage;

namespace TaxiTouchClient
{
    public partial class Taxi_details_demande : PhoneApplicationPage
    {
        PhoneApp1.ServiceReference1.Demande demande;

        public Taxi_details_demande()
        {
            InitializeComponent();
            demande = (PhoneApp1.ServiceReference1.Demande)PhoneApplicationService.Current.State["demandeSelected"];
            txtDepart.Text = demande.Adresse_Origine;
            txtDestination.Text = demande.Adresse_Destination;
            txtPersonne.Text = demande.Nombre_Personne.ToString();
            txtDateDebut.Text = String.Format("{0:dd/MM/yyyy HH:mm}", demande.Date_Debut);
        }

        private void Choisir_TaxiDetailsDemande_Click(object sender, RoutedEventArgs e)
        {
            PhoneApp1.ServiceReference1.Service1Client service = new PhoneApp1.ServiceReference1.Service1Client();
            service.ValidateDemandeCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(service_ValidateDemandeCompleted);
            PhoneApp1.ServiceReference1.Taxi taxi = (PhoneApp1.ServiceReference1.Taxi) IsolatedStorageSettings.ApplicationSettings["Taxi"];
            service.ValidateDemandeAsync(demande.ID_Demande,taxi.IDTaxi);
        }

        void service_ValidateDemandeCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            MessageBox.Show("ok");
            IsolatedStorageSettings.ApplicationSettings["DemandeActuelleTaxi"] = demande;
            NavigationService.Navigate(new Uri("/Pages/Taxi_accueil.xaml", UriKind.Relative));
        }

        private void Retour_TaxiDetailsDemande_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }
    }
}